﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Model
{
    public class FileItem
    {
        private int categoryID;
        private DateTime date;
        private string description;
        private int downCount;
        private long fileSize;
        private int id;
        private string ip;
        private string name;
        private string path;

        public FileItem()
        {
            this.id = -1;
            this.path = string.Empty;
            this.name = string.Empty;
            this.description = string.Empty;
            this.ip = string.Empty;
            this.date = DateTime.Now;
            this.categoryID = -1;
            this.downCount = 0;
        }

        public FileItem(int id, string path, string name, string description, string ip, DateTime date, int categoryID, int downCount)
        {
            this.ID = id;
            this.Path = path;
            this.Name = name;
            this.Description = description;
            this.Ip = ip;
            this.Date = date;
            this.CategoryID = categoryID;
            this.DownCount = downCount;
        }

        public void IncDownCount()
        {
            this.downCount++;
        }

        public int CategoryID
        {
            get
            {
                return this.categoryID;
            }
            set
            {
                if (value == -1)
                {
                    throw new Exception("Виберіть категорію");
                }
                this.categoryID = value;
            }
        }

        public DateTime Date
        {
            get
            {
                return this.date;
            }
            set
            {
                this.date = value;
            }
        }

        public string Description
        {
            get
            {
                return this.description;
            }
            set
            {
                if (value == string.Empty)
                {
                    throw new Exception("Поле опису не може бути пустим");
                }
                this.description = value;
            }
        }

        public int DownCount
        {
            get
            {
                return this.downCount;
            }
            set
            {
                this.downCount = value;
            }
        }

        public string FileSize
        {
            get
            {
                if (this.fileSize < 0x400L)
                {
                    return (this.fileSize.ToString() + " б");
                }
                if ((this.fileSize >= 0x400L) && (this.fileSize < 0x100000L))
                {
                    return string.Format("{0:G4} Кб", ((double)this.fileSize) / 1024.0);
                }
                return string.Format("{0:G4} Мб", ((double)this.fileSize) / 1048576.0);
            }
            set
            {
                this.fileSize = Convert.ToInt64(value);
            }
        }

        public int ID
        {
            get
            {
                return this.id;
            }
            set
            {
                this.id = value;
            }
        }

        public string Ip
        {
            get
            {
                return this.ip;
            }
            set
            {
                this.ip = value;
            }
        }

        public string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                if (value == string.Empty)
                {
                    throw new Exception("Поле імені не може бути пустим");
                }
                this.name = value;
            }
        }

        public string Path
        {
            get
            {
                return this.path;
            }
            set
            {
                if (value == string.Empty)
                {
                    throw new Exception("Помилка завантаження");
                }
                this.path = value;
            }
        }
    }
}
